package com.eastfair.es.entity;

import com.eastfair.core.context.ContextUtil;
import com.eastfair.core.context.StaticContextUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.*;

import java.io.Serializable;
import java.util.Date;

@Data
@Document(indexName = "alllog", type = "_doc")
//指定映射es中的索引
@Mapping(mappingPath = "productIndex.json") // 解决IK分词不能使用问题
public class AllLog implements Serializable {
    @Id
    @Field(index = true, normalizer = "lowercase" , store = true, type = FieldType.Keyword)
    @ApiModelProperty(value = "主键id")
    private String id;


    //    @Field(index = false, store = true, type = FieldType.Date, format = DateFormat.basic_date_time)
    //date_time_no_millis
//    @Field( type = FieldType.Date,format = DateFormat.custom,
//            pattern = "yyyy-MM-dd HH:mm:ss")//不行没有格式
    @Field(index = false, store = true, type = FieldType.Date, format = DateFormat.date_time,pattern = "yyyy-MM-ddTHH:mm:ss.SSSZ")
//    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern ="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "创建时间")
    //时区问题，需要按中国时间 timezone
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS",timezone = "GMT+8")
    private Date dateTime;


    //日志唯一时间，用于排序
    @Field(index = false, normalizer = "lowercase" , store = true, type = FieldType.Long)
    @ApiModelProperty(value = "日志唯一时间，用于排序")
    private Long dtTime;


    @Field(index = false, normalizer = "lowercase" ,store = false, type = FieldType.Text)
    @ApiModelProperty(value = "记录调用的IP地址")
    private String clientIp;


    @Field(index = false, normalizer = "lowercase" ,store = false, type = FieldType.Keyword)
    @ApiModelProperty(value = "日志信息")
    private String detail;

    @Field(index = false, normalizer = "lowercase" ,store = false, type = FieldType.Text)
    @ApiModelProperty(value = "日志级别")
    private String logLevel;

    @Field(index = false, normalizer = "lowercase" ,store = false, type = FieldType.Text)
    @ApiModelProperty(value = "线程名称")
    private String threadName;

    @Field(index = false, normalizer = "lowercase" ,store = false, type = FieldType.Text)
    @ApiModelProperty(value = "类名称")
    private String className;

    @Field(index = false, normalizer = "lowercase" ,store = false, type = FieldType.Text)
    @ApiModelProperty(value = "创建时间")
    private String dateTimeStr;



    //日志唯一时间，用于排序
    @Field(index = false, normalizer = "lowercase" , store = true, type = FieldType.Integer)
    @ApiModelProperty(value = "排序")
    private int seq;


    @Field(index = false, normalizer = "lowercase" ,store = false, type = FieldType.Text)
    @ApiModelProperty(value = "应用运行所属IP地址")
    private String serverName;



    @Field(index = false, normalizer = "lowercase" ,store = false, type = FieldType.Text)
    @ApiModelProperty(value = "记录服务IP地址")
    private String serverIp;

    @Field(index = false, normalizer = "lowercase" ,store = false, type = FieldType.Text)
    @ApiModelProperty(value = "链路id")
    private String traceId;

    @Field(index = false, normalizer = "lowercase" ,store = false, type = FieldType.Text)
    @ApiModelProperty(value = "应用名")
    private String appName;

    @Field(index = false, normalizer = "lowercase" ,store = false, type = FieldType.Text)
    @ApiModelProperty(value = "方法名")
    private String method;

    @Field(index = false, normalizer = "lowercase" ,store = false, type = FieldType.Integer)
    @ApiModelProperty(value = "方法行数")
    private int line;

    @Field(index = false, normalizer = "lowercase" ,store = false, type = FieldType.Integer)
    @ApiModelProperty(value = "端口")
    private int post;


    @Field(index = false, normalizer = "lowercase" ,store = false, type = FieldType.Text)
    @ApiModelProperty(value = "应用环境")
    private String env;

    /**
     * 操作人id
     */
    @Field(index = false, normalizer = "lowercase" ,store = false, type = FieldType.Text)
    @ApiModelProperty(value = "操作人id")
    private Long userId;

    /**
     * 操作人名称
     */
    @Field(index = false, normalizer = "lowercase" ,store = false, type = FieldType.Text)
    @ApiModelProperty(value = "操作人名称")
    private String userName;

    @Field(index = false, normalizer = "lowercase" ,store = false, type = FieldType.Keyword)
    @ApiModelProperty(value = "header参数")
    private String headParam;


}
